import 'package:flutter/material.dart';
import 'package:hud/hud.dart';

class HudDemoPage extends StatefulWidget {
  const HudDemoPage({super.key});

  @override
  State<HudDemoPage> createState() => _HudDemoPageState();
}

class _HudDemoPageState extends State<HudDemoPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Hud example'),
      ),
      body: Column(
        children: [
          ListTile(
            title: const Text('toast'),
            onTap: () {
              Hud.toast('我是一个toast');
            },
            shape: const UnderlineInputBorder(
                borderSide: BorderSide(color: Color(0xffeeeeee))),
          ),
          ListTile(
            title: const Text('loadding 5秒后消失'),
            shape: const UnderlineInputBorder(
                borderSide: BorderSide(color: Color(0xffeeeeee))),
            onTap: () async {
              Hud.show();
              await Future.delayed(Duration(seconds: 5));
              Hud.dismiss();
            },
          ),
          ListTile(
            title: const Text('当提示toast与loadding冲突时，优先toast显示完成'),
            shape: const UnderlineInputBorder(
                borderSide: BorderSide(color: Color(0xffeeeeee))),
            onTap: () async {
              Hud.show();
              await Future.delayed(Duration(milliseconds: 200));

              Hud.toast('我是第一个toast');
              await Future.delayed(Duration(milliseconds: 200));
              await Hud.dismiss();
              Hud.show();
              await Future.delayed(Duration(milliseconds: 1800));
              Hud.show();
              await Future.delayed(Duration(milliseconds: 5000));
              Hud.dismiss();
            },
          ),
        ],
      ),
    );
  }
}
